package com.mzy.redis;

import org.junit.jupiter.api.Test;
import redis.clients.jedis.Jedis;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

public class JedisDemo {

    @Test
    public void testJedis() {
        Jedis jedis = new Jedis("192.168.70.100", 6379);
        jedis.auth("mzy666");


        /*Set<String> keys = jedis.keys("*");
        keys.forEach(System.out::println);

        jedis.set("k3", "hello-jedis");
        System.out.println(jedis.get("k3"));
        System.out.println(jedis.ttl("k3"));
        jedis.expire("k3", 10);

        jedis.lpush("list", "1" , "2" , "3");

        List<String> list = jedis.lrange("list", 0, -1);
        list.forEach(System.out::println);
*/
        // 测试 set 集合

/*        jedis.sadd("s1", "1", "1", "2", "3", "3", "2");
        Set<String> s1 = jedis.smembers("s1");
        s1.forEach(System.out::print);
        System.out.println();

        System.out.println(jedis.sismember("s1", "3"));

        System.out.println(jedis.scard("s1"));*/


        // 测试 hash

/*        jedis.hset("h1", "k1", "v1");
        System.out.println(jedis.hget("h1", "k1"));
        Map<String, String> map = new HashMap<>();
        map.put("mzy", "qmf");
        map.put("m", "q");
        map.put("z", "m");
        map.put("a", "b");

        jedis.hset("h3", map);

        Set<String> h3Keys = jedis.hkeys("h3");
        List<String> h3Vals = jedis.hvals("h3");
        System.out.println(h3Keys);
        System.out.println(h3Vals);*/

        // 测试 zset
        jedis.zadd("s1", 1.1, "v1");
        Map<String, Double> map = new HashMap<>();
        map.put("v1", 1.1);
        map.put("v2", 1.2);
        map.put("v3", 1.6);
        jedis.zadd("s2",  map);
        System.out.println(jedis.zcard("s1"));
        System.out.println(jedis.zcard("s2"));
        System.out.println(jedis.zrange("s2", 0, -1));
    }
}
